
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JOptionPane;

public class SqlDao {

	private  Connection conn;
	public SqlDao(Connection conn) {
		this.conn = conn;
	}

	//处理增删改业务
	public int update(String sql) {
		System.out.println(sql+"已执行");
		return 0;
	}
	public Vector<Vector<String>> select(String sql){
		Vector<Vector<String>> v = new Vector<>();
		try {
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
			//将rs转为vector
			while(rs.next()) {
				//获取下一条记录
				String s1 = rs.getString(1);
				String s2 = rs.getString(2);
				String s3 = rs.getString(3);
				String s4 = rs.getString(4);
				Vector<String> temp = new Vector<>();
				temp.add(s1);
				temp.add(s2);
				temp.add(s3);
				temp.add(s4);
				v.add(temp);
			}
			rs.close();
			stmt.close();
		} catch (SQLException e) {
			
		}catch(NullPointerException e) {
			JOptionPane.showMessageDialog(null, "请连接数据库");
		}
		return v;
	}
}
